Ext.define('qjtravel.view.CommentAdd', {
    extend: 'Ext.Panel',
    xtype: 'commentAdd',

    requires: [
        'Ext.data.Store',
        'Ext.form.FieldSet',
        'Ext.field.Toggle'
    ],

    config: {
        scrollable: false,
        height: '100%',
        items: [
            {
                xtype: 'titlebar',
                docked: 'top',
                items: {
                    xtype: 'button',
                    text: '返回',
                    handler: function () {
                        var backid = Ext.Viewport.getInnerItems().length - 2;
                        Ext.Viewport.remove(this.up('commentAdd'), true);
                        Ext.Viewport.setActiveItem(backid);

                    }
                }
            },
            {
                xtype: 'fieldset',
                algin: 'center',
                items: {
                    xtype: 'textareafield',
                    height: '100%',
                    id: 'commentText',
                    placeHolder: '请输入您的反馈意见',
                    style: 'height:140px;'
                }
            },
            {
                layout: 'hbox',
                style: 'margin-top:20px',
                items: [
                    {
                        xtype: 'button',
                        text: '提交',
                        width: '60%',
                        action: 'asksubmit',
                        style: 'margin:0 2% 0 2%;height:45px;',
                        handler: function () {
                            Ext.Viewport.mask({xtype: 'loadmask' });
                            var message = Ext.getCmp('commentText').getValue();
                            if (message == "") {
                                Ext.Viewport.unmask();
                                cordova.exec(function (message) {
                                }, function (error) {
                                }, "Messages", "showMsg", ['您还没有填写留言内容哦！']);
                                return false;
                            } else {
                                Ext.Ajax.request({
                                    url: Global.api_url + '/cloud/1/message_add',
                                    method: 'POST',
                                    params: {
                                        cadid: '6',
                                        messages: message,
                                        mesType: '文字'
                                    },
                                    scope: this,
                                    success: function (result) {
                                        Ext.Viewport.unmask();
                                        var result = Ext.decode(result.responseText);
                                        if (result.Variables.Result.code == 0) {
                                            Ext.Viewport.remove(this.up('commentAdd'), true);
                                            Ext.Viewport.remove(Ext.Viewport.child('comment'), true);
                                            Ext.Viewport.animateActiveItem('comment', {type: 'slide', direction: 'right'});
                                        } else {
                                            cordova.exec(function (message) {
                                            }, function (error) {
                                            }, "Messages", "showMsg", [result.Variables.Message.messagestr]);
                                            return false;
                                        }
                                    },
                                    failure: function () {
                                        Ext.Viewport.unmask();
                                        cordova.exec(function (message) {
                                        }, function (error) {
                                        }, "Messages", "showMsg", ['请求失败', '服务器维护中....']);
                                        return false;
                                    }

                                })
                            }
                        }

                    },
                    {
                        xtype: 'button',
                        text: '取消',
                        width: '34%',
                        style: 'margin:0 2% 0 0;height:45px;',
                        handler: function () {
                            Ext.Viewport.animateActiveItem('comment', {type: 'slide', direction: 'right'});
                        }
                    }
                ]
            }

        ], listeners: {
            back: function () {
                var backid = Ext.Viewport.getInnerItems().length - 2;
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
                Ext.Viewport.setActiveItem(backid);
            }
        }
    }

});


